package flex.cc.uac.controller;

import flex.cc.PublicUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import flex.cc.uac.entity.UacCalllerEntity;
import flex.cc.uac.service.UacCalllerService;
import flex.cc.wrapper.WrapMapper;
import flex.cc.wrapper.Wrapper;

import java.util.Map;

/**
 * 调用放管理
 *
 * @author jiayongchao
 * @email jiayongchao@sinosoft.com.cn
 * @date 2021-05-19 14:53:27
 */
@RestController
@RequestMapping("/uac/uaccalller")
public class UacCalllerController {
	@Autowired
	private UacCalllerService uacCalllerService;
	
	@PostMapping("/queryListWithPage")
	public Wrapper<Page<UacCalllerEntity>> list(@RequestBody UacCalllerEntity uacCalllerEntity) {
		Page<UacCalllerEntity> page = new Page<>(uacCalllerEntity.getPageNum(), uacCalllerEntity.getPageSize());
		return WrapMapper.ok(uacCalllerService.page(page, new QueryWrapper<UacCalllerEntity>()
				                                                            .eq(!PublicUtil.isEmpty(uacCalllerEntity.getCallerCode()),"caller_code",uacCalllerEntity.getCallerCode())
																			.eq(!PublicUtil.isEmpty(uacCalllerEntity.getCallerName()),"caller_name",uacCalllerEntity.getCallerName())
				                                                            .orderByDesc("created_time"))) ;
	}

	@ApiOperation("调用方新增数据")
	@PostMapping("/addCallerInfo")
	public Wrapper<String> addCalllerInfo(@RequestBody Map map){
		String returnDate = uacCalllerService.addCalllerInfo(map);
		return  WrapMapper.ok(returnDate);
	}

	@ApiOperation("调用方删除数据")
	@PostMapping("/deleteCallerInfoById/{id}")
	public Wrapper<Integer> deleteCallerInfoById(@ApiParam(name = "id", value = "数据ID") @PathVariable Long id){
		uacCalllerService.deleteCallerInfoById(id);
		return  WrapMapper.ok();
	}


	@ApiOperation("根据ID查询调用方数据")
	@PostMapping("/queryCallerInfoById/{id}")
	public Wrapper<UacCalllerEntity> queryCallerInfoById(@ApiParam(name = "id", value = "数据ID") @PathVariable Long id){
		UacCalllerEntity entity = uacCalllerService.queryCallerInfoById(id);
		return  WrapMapper.ok(entity);
	}
}
